package com.speedricemanager.activity.home.registeframent.presenter;

import android.content.Context;
import android.content.Intent;

import com.jbm.core.iface.IAcross;
import com.jbm.jsm.iface.TaskMouldEntity;
import com.speedricemanager.activity.home.fragmenadapter.RegisterauditAdapter;
import com.speedricemanager.activity.home.intface.IntegerFaceOr;
import com.speedricemanager.activity.home.registeframent.mode.RegisterauditFramentMode;
import com.speedricemanager.activity.home.registeframent.view.RegisterauditFrament_Inter;
import com.speedricemanager.activity.home.registermodepart.RegisterModePart;
import com.speedricemanager.interfaces.DialogSuccess;
import com.speedricemanager.other.base.BaseAty;

import java.util.ArrayList;

/**
 * Created by 李征 on 2017/12/17.
 */

public class RegisterauditFramentPersenterac implements RegisterauditFramentPersenter_Inter{
    private Context context;
    private RegisterauditFrament_Inter registerauditFrament_inter;
    private int star = 0;
    private int pag = 0;
    ArrayList<TaskMouldEntity> arrayList;
    RegisterauditAdapter registerauditAdapter;
private RegisterauditFramentMode registerauditFramentMode;
    public RegisterauditFramentPersenterac(Context context, RegisterauditFrament_Inter registerauditFrament_inter) {
        this.context = context;
        this.registerauditFrament_inter = registerauditFrament_inter;
        registerauditFramentMode=new RegisterauditFramentMode();

        arrayList=new ArrayList<>();
    }


    @Override
    public void initData() {

    }

    @Override
    public void getOnPullLoad() {

    }

    /**
     * 搜索模板列表
     */
    @Override
    public void seekList() {
        ((BaseAty)context).onLoad();
        registerauditFramentMode.getModuleList(registerauditFrament_inter.editousuo().getText().toString(), registerauditFrament_inter.getTags(), registerauditFrament_inter.getstatic(), registerauditFrament_inter.startime().getText().toString(), registerauditFrament_inter.enttime().getText().toString(), 0, 0, new IntegerFaceOr() {
            @Override
            public void getSucces(Object o) {
                ((BaseAty)context).loadDismiss();
                TaskMouldEntity ta=(TaskMouldEntity)o;
                if (ta.getMouldList()!=null){
                    registerauditFrament_inter.dianfupullLoadMoreRecyclerView().setPullLoadMoreCompleted();
                    arrayList.clear();
                    arrayList.addAll(ta.getMouldList());
                    registerauditAdapter=new RegisterauditAdapter(context,arrayList);
                    registerauditFrament_inter.dianfupullLoadMoreRecyclerView().setAdapter(registerauditAdapter);
                    registerauditAdapter.setOnClickListener(new RegisterauditAdapter.onClickListener() {
                        @Override
                        public void onClickListener(TaskMouldEntity taskMouldEntity) {
                            context.startActivity(new Intent(context,RegisterModePart.class).putExtra("tmid",taskMouldEntity.getTmId()));
                        }
                    });
                    registerauditAdapter.getJujueshenqing(new RegisterauditAdapter.GetonJujue() {
                        @Override
                        public void getJuJieShenQing(final int id) {
                            ((BaseAty)context).editAlert("请填写拒绝原因", new DialogSuccess() {
                                @Override
                                public void option(String password) {
                                    ((BaseAty)context).onLoad();
                                    registerauditFramentMode.AuditTaskMoulds(id,3,password ,"","","","",null,null,"","","","",null,new IntegerFaceOr() {
                                        @Override
                                        public void getSucces(Object o) {
                                            ((BaseAty)context).loadDismiss();
                                            IAcross iAcross=(IAcross)o;

                                        }

                                        @Override
                                        public void getError(Object o) {
                                            ((BaseAty)context).loadDismiss();
                                            IAcross iAcross=(IAcross)o;
                                            ((BaseAty)context).errorAlert(iAcross.m_info);
                                        }
                                    });
//                                    registerauditFramentMode.AuditTaskMoulds();
                                }
                            });
                        }
                    });
                }else {
                    registerauditFrament_inter.dianfupullLoadMoreRecyclerView().setPullLoadMoreCompleted();
                }
            }

            @Override
            public void getError(Object o) {
                TaskMouldEntity ta=(TaskMouldEntity)o;
                ((BaseAty)context).loadDismiss();
                ((BaseAty)context).errorAlert(ta.m_info);
            }});
    }


}
